package cn.matrix42.potoo.format.markdown.element;

import java.io.Serializable;
import java.util.List;

import cn.matrix42.potoo.format.markdown.conf.MarkdownContext;

public abstract class MarkdownElement implements Serializable {

    protected MarkdownContext context = new MarkdownContext();

    public void setup(MarkdownContext context) {
        this.context = context;
    }

    abstract public List<String> toMarkdownStringList();

    public String toMarkdownString() {
        StringBuilder builder = new StringBuilder();
        List<String> markdownStringList = toMarkdownStringList();
        if (markdownStringList != null) {
            for (String markdownString : markdownStringList) {
                builder.append(markdownString);
                builder.append(context.getConfig().getEof());
            }
        }
        return builder.toString();
    }

}
